#include<cstdio>//uncle-lu
#include<algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

const int mod = 19650827;
int n;
int line[1010];
int F[1010][1010][2];

int main()
{
	read(n);
	for (int i = 1; i <= n; i++) 
		read(line[i]);

	for (int i = 1; i <= n; i++) 
		F[i][i][0] = 1;

	for (int len = 2; len <= n; len++) 
	{
		for (int l = 1; l <= n - len + 1; l++) 
		{
			int r = l + len - 1;
			if(line[l] < line[l+1])
				F[l][r][0] += F[l+1][r][0];
			if(line[l] < line[r])
				F[l][r][0] += F[l+1][r][1];
			if(line[r] > line[r-1])
				F[l][r][1] += F[l][r-1][1];
			if(line[r] > line[l])
				F[l][r][1] += F[l][r-1][0];
			F[l][r][0] %= mod;
			F[l][r][1] %= mod;
		}
	}

	printf("%d", (F[1][n][0] + F[1][n][1]) % mod);
	return 0;
}
